#include <stdio.h>
#include <iostream>
#include <cstring>

#include "SeqList.h"
#include "LinkedList.h"
#include "String.h"
#include "Tree.h"

using namespace std;

 void seq() {
 	SeqList l = initSeqList();
 	print(l);
 	printf("--------------------------------\n");

 	extend(l, 10);
 	print(l);

 	printf("--------------------------------\n");

 	addToLast(l, 1);
 	addToLast(l, 2);
 	addToLast(l, 3);
 	print(l);

 	printf("--------------------------------\n");

 	addToFirst(l, 0);
 	print(l);

 	printf("--------------------------------\n");

 	addToIndex(l, 4, 4);
 	print(l);

 	printf("--------------------------------\n");

 	removeToLast(l);
 	print(l);

 	printf("--------------------------------\n");

 	removeToFirst(l);
 	print(l);

 	printf("--------------------------------\n");

 	removeToIndex(l, 1);
 	print(l);

 	printf("--------------------------------\n");
 }

 void linkedNoHead() {
 	LinkedList list = initLinkedListNoHead();
 	cout << &list << "\n\n-------------\n" << endl;

 	bool flag = isEmptyNoHead(list);
 	cout << boolalpha;
 	cout << flag << "\n\n-------------\n" << endl;

 	noHeadInsertToFirst(list, 6);
 	noHeadInsertToFirst(list, 3);
 	noHeadInsertToFirst(list, 2);
 	noHeadInsertToFirst(list, 1);
 	noHeadInsertToFirst(list, 0);

 	noHeadPrint(list);

 	LinkedNode *node = noHeadGetByIndex(list, 3);
 	LinkedNode *node1 = noHeadGetByIndex(list, 4);
 	cout << "获取数据：" << node->data << "\n" << endl;
 	cout << "获取数据：" << node1->data << "\n" << endl;

 	bool result1 = insertByNodeAfter(node, 4);
 	bool result2 = insertByNodeFront(node1, 5);
 	cout << result1 << "\n" << endl;
 	cout << result2 << "\n" << endl;
 	noHeadPrint(list);

 	bool result3 = noHeadInsterByIndex(list, 7, 10);
 	bool result4 = noHeadInsterByIndex(list, 7, 9);
 	bool result5 = noHeadInsterByIndex(list, 6, 7);
 	bool result6 = noHeadInsterByIndex(list, 6, 6);
 	cout << result3 << "\n" << endl;
 	cout << result4 << "\n" << endl;
 	cout << result5 << "\n" << endl;
 	cout << result6 << "\n" << endl;
 	noHeadPrint(list);

 	bool result7 = noHeadModifyByIndex(list, 8, 6);
 	cout << result7 << "\n" << endl;
 	noHeadPrint(list);

 	bool result8 = noHeadRemoveFirst(list);
 	bool result9 = noHeadRemoveFirst(list);
 	bool result10 = noHeadRemoveFirst(list);
 	cout << result8 << "\n" << endl;
 	cout << result9 << "\n" << endl;
 	cout << result10 << "\n" << endl;
 	noHeadPrint(list);

 	bool result11 = noHeadRemoveByIndex(list, 1);
 	cout << result11 << "\n" << endl;
 	noHeadPrint(list);

 	LinkedNode *node2 = noHeadGetByValueFirst(list, 9);
 	cout << node2->data << "\n" << endl;
 	cout << node2->next->data << "\n" << endl;

 	int arr[] = {1, 1, 2, 1, 4};
 	LinkedList createList = noHeadCreateByTail(&arr[0], sizeof(arr) / sizeof(arr[0]));
 	noHeadPrint(createList);

 	bool result12 = noHeadModifyByValue(createList, 1, 100);
 	cout << result12 << "\n" << endl;
 	noHeadPrint(createList);

 	int arr1[] = {5, 4, 3, 2, 1};
 	LinkedList createList1 = noHeadCreateByHead(&arr1[0], sizeof(arr1) / sizeof(arr1[0]));
 	noHeadPrint(createList1);

 	LinkedList createList2 = noHeadInversion(createList1);
 	noHeadPrint(createList2);
 }

 void linkedHaveHead() {
 	cout << boolalpha;

 	LinkedList list = initLinkedListHaveHead();
 	cout << &list->next << "\n" << endl;

 	bool flag = isEmptyHaveHead(list);
 	cout << flag << "\n" << endl;

 	bool result = haveHeadInsertToFirst(list, 6);
 	haveHeadInsertToFirst(list, 3);
 	haveHeadInsertToFirst(list, 2);
 	haveHeadInsertToFirst(list, 1);
 	haveHeadInsertToFirst(list, 0);

 	haveHeadPrint(list);

 	LinkedNode *node = haveHeadGetByIndex(list, 3);
 	LinkedNode *node1 = haveHeadGetByIndex(list, 4);
 	cout << "获取数据：" << node->data << "\n" << endl;
 	cout << "获取数据：" << node1->data << "\n" << endl;

 	bool result1 = insertByNodeAfter(node, 4);
 	bool result2 = insertByNodeFront(node1, 5);
 	cout << result1 << "\n" << endl;
 	cout << result2 << "\n" << endl;
 	haveHeadPrint(list);

 	bool result3 = haveHeadInsertByIndex(list, 7, 10);
 	bool result4 = haveHeadInsertByIndex(list, 7, 9);
 	bool result5 = haveHeadInsertByIndex(list, 6, 7);
 	bool result6 = haveHeadInsertByIndex(list, 6, 6);
 	cout << result3 << "\n" << endl;
 	cout << result4 << "\n" << endl;
 	cout << result5 << "\n" << endl;
 	cout << result6 << "\n" << endl;
 	haveHeadPrint(list);

 	bool result7 = haveHeadModifyByIndex(list, 8, 8);
 	cout << result7 << "\n" << endl;
 	haveHeadPrint(list);

 	bool result8 = haveHeadRemoveFirst(list);
 	bool result9 = haveHeadRemoveFirst(list);
 	bool result10 = haveHeadRemoveFirst(list);
 	cout << result8 << "\n" << endl;
 	cout << result9 << "\n" << endl;
 	cout << result10 << "\n" << endl;
 	haveHeadPrint(list);

 	bool result11 = haveHeadRemoveByIndex(list, 4);
 	cout << result11 << "\n" << endl;
 	haveHeadPrint(list);

 	LinkedNode *node2 = haveHeadGetValueFirst(list, 9);
 	cout << node2->data << "\n" << endl;
 	cout << node2->next->data << "\n" << endl;

 	int arr[] = {1, 1, 2, 1, 4};
 	LinkedList createList = haveHeadCreateByTail(&arr[0], sizeof(arr) / sizeof(arr[0]));
 	haveHeadPrint(createList);

 	bool result12 = haveHeadModifyByValue(createList, 1, 100);
 	cout << result12 << "\n" << endl;
 	haveHeadPrint(createList);

 	cout << endl;

 	int arr1[] = {5, 4, 3, 2, 1};
 	LinkedList createList1 = haveHeadCreateByHead(&arr1[0], sizeof(arr1) / sizeof(arr1[0]));
 	haveHeadPrint(createList1);

 	cout << endl;

 	LinkedList createList2 = haveHeadInversion(createList1);
 	haveHeadPrint(createList2);
 }

void StringTest() {
	char chars[] = {'h', 'e', 'l', 'l', 'o', ',', 'w', 'o', 'r', 'l', 'd'};
	String string;
	Assign(string, chars, sizeof(chars) / sizeof(chars[0]));
	print(string);
	int len = length(string);
	printf("%d\n", len);
	String subString = subStr(string, 2, 5);
	print(subString);
	int compareResult = compare(string, subString);
	printf("%d\n", compareResult);
	int subIndex = index(string, subString);
	printf("%d\n", subIndex);
	int subIndex1 = index1(string, subString);
	printf("%d\n", subIndex1);
	int kmpIndex = kmp(string, subString);
	printf("%d\n", kmpIndex);

	char chars1[] = {'h', 'e', 'l', 'l', 'o'};
	String string1;
	Assign(string1, chars1, sizeof(chars1) / sizeof(chars1[0]));

	char chars2[] = {'l', 'l'};
	String string2;
	Assign(string2, chars2, sizeof(chars2) / sizeof(chars2[0]));

	int subIndex2 = index(string1, string2);
	printf("%d\n", subIndex2);
	int subIndex3 = index1(string1, string2);
	printf("%d\n", subIndex3);
	int kmpIndex1 = kmp(string1, string2);
	printf("%d\n", kmpIndex1);
}

void TreeTest() {
	Tree treeFirst = init();
	test(treeFirst);
	printf("前序遍历：");
	firstCreate(treeFirst);
	printf("\n");

	Tree treeInOrder = init();
	test(treeInOrder);
	printf("中序遍历：");
	inOrderPrint(treeInOrder);
	printf("\n");

	Tree treePostOrder = init();
	test(treePostOrder);
	printf("后序遍历：");
	postOrderPrint(treePostOrder);
	printf("\n");
}

int main() {
//	linkedNoHead();
//	linkedHaveHead();
	StringTest();
//	TreeTest();
}
/*char *convert(char *s, int numRows) {
	int length = strlen(s);
	char *news;
	char temp[numRows][(length / numRows) + ((length % numRows) == 0 ? 0 : 1)];
	int j = 0;
	for (int i = 0; i < length; i++) {
		if (i + 1 < numRows) {
			temp[i][j] = s[i];
		} else {
			temp[i % numRows][j] = s[i];
		}
		j++;
	}
	int index = 0;
	for (int i = 0; i < (length / numRows) + ((length % numRows) == 0 ? 0 : 1); i++) {
		for (int k = 0; k < numRows; k++) {
			if (temp[i][j] != '\0') {
				news[index] = temp[i][j];
				index++;
			}
		}
	}
	return news;
}*/